<template>
	<view class="body">
		<view v-if="loading">
			<loading></loading>
		</view>
		<view class="container" v-else>
			<view class="reportView ">
				<view class="container-1"  :data-index="index" v-for="(i, index) in cateList">
					<view class="left" @click="clickToBank(i.id)">
						<view class="top">
							<text class="title">分类名称：</text>
							<text>{{i.categoryName}}</text>
							<text class="blue">已上传{{i.courseCount}}节</text>
						</view>
						<view class="bottom">
							<text>创建时间:{{parseTime(i.createTime,'{y}-{m}-{d}')}}</text>
							<text>分类ID:{{i.id}}</text>
							<text>{{i.type == 1?'公有':'私有'}}</text>
							<text :class="i.status == 0?'green':'red'">{{i.status == 0?'开启':'关闭'}}</text>
						</view>
					</view>
					<view class="right" @click="open(i)">
						<text class="dot"></text>
						<text class="dot"></text>
						<text class="dot"></text>
					</view>
					<!-- <view class="update-1" @click="update(i.id)">
						修改
					</view>
					<view class="delete-1" @click="delData">
						删除
					</view> -->
				</view>
				<view class="load-more">
					<uni-icons v-if="loadShow" type="spinner-cycle" size="30"></uni-icons>
					<text  v-if="botShow">已经到底了</text>
				</view>
			</view>
			<view class="topTitle">
				<text class="btn" @tap="toAdd">新增类目</text>
			</view>
		</view>
		<uni-popup ref="popup" type="bottom">
			<view class="popup">
				<text @click="update">修改</text>
				<text @click="delData"  class="del">删除</text>
				<text class="cancel" @click="close">取消</text>
			</view>
		</uni-popup>
		<show-modal></show-modal>
	</view>
	
</template>
<script>
	import { getAdminCate,deleteSubjectCategory } from '@/api/exam/activity.js'
	import {parseTime } from '@/utils/ruoyi'
	import loading from '@/components/loading/loading'
	export default{
		data(){
			return{
				leftStyle: 0,
				startX: 0,
				hiddenFlag: true,
				delBtnWidth: 220,
				act_touch: null,
				cateList:[],
				pageForm:{
					pageNo:1,
					pageSize:10,
					parentId:1
				},
				active:null,
				parseTime,
				loadShow:false,
				botShow:false,
				loading:true,
			}
		},
		onLoad() {
			
		},
		onShow(){
			this.cateList=[]
			this.getcate()
		},
		onReachBottom(){
			if(!this.botShow){
				this.loadShow = true
				this.pageForm.pageNo ++ ;
				this.getcate()
			}
			
		},
		methods:{
			
			open(e){
				this.active=e
				// 通过组件定义的ref调用uni-popup方法 ,如果传入参数 ，type 属性将失效 ，仅支持 ['top','left','bottom','right','center']
				this.$refs.popup.open('bottom')
			},
			close() {
				this.$refs.popup.close()
			},
			getcate(){
				getAdminCate(this.pageForm).then(res=>{
					if(res.data.list.length > 0){
						this.cateList.push(...res.data.list)
						this.loadShow = false
					}else{
						this.loadShow = false
						this.botShow = true
					}
					this.loading = false
					
				})
			},
			toAdd(){
				this.$tab.navigateTo(`/pages/work/teach/addCate`)
			},
			
			//删除方法
			delData() {
				let that = this
				this.$showModal({
					title: '',
					icon:'/static/images/warning2.png',
					content: '是否删除？',
					cancelText:"取消",
					confirmText:"确定",
					cancelBackgroundColor:'#508CFF',
					confirmBackgroundColor:'#508CFF',
					success(res) {
						if (res.confirm) {
							 that.delCate()
						} else if (res.cancel) {
						}			
					}
				})
			},
			delCate(){
				deleteSubjectCategory(this.active.id).then(res=>{
					this.$modal.msgSuccess("删除成功")
					this.cateList=[]
					this.getcate()
					this.close()
					
				})
			},
			clickToBank(e){
				this.$tab.navigateTo(`/pages/work/teach/courseList?id=` + e)
				this.close()
			},
			update(){
				this.$tab.navigateTo(`/pages/work/teach/addCate?id=` + this.active.id)
				this.close()
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #fff;
		height: initial;
		overflow-y: initial;
		min-height:100vh;
	}
	.container{
		background-color: #fff;
		height:100vh;
		padding-top: 20px;
		
		.reportView{
			width: calc(100% - 80rpx);
			height: calc(100vh - 300rpx);
			overflow: scroll;
			margin: 0 auto;
			font-size: 14px;
			font-family: Inter-Thin, Inter;
			
		}
		
		.container-1 {
			margin-top: 26rpx;
			margin-bottom: 20upx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding:10px 5px;
			border-bottom:  1px solid #E1E1E1;
			
			.left{
				text{
					line-height: 30px;
					font-size: 14px;
					font-family: Inter-Regular, Inter;
					font-weight: 400;
					color: #5E5E5E;
				}
				.top{
					display: flex;
					justify-content: space-between;
					.title{
						font-family: Inter-Bold, Inter;
						font-weight: bold;
						color: #000000;
					}
					.blue{
						font-size: 12px;
						color: #508CFF;
					}
				}
				.bottom{
					display: flex;
					justify-content: space-between;
					margin-top: 10px;
					text{
						margin-right: 8px;
						font-size: 12px;
					}
					.green{
						color: #50B987;
					}
					.red{
						color: #F26D6D;
					}
				}
				
			}
			.right{
				display: flex;
				.dot{
					width: 5px;
					height: 5px;
					background: #A3A3A3;
					opacity: 1;
					margin-right: 5px;
					border-radius: 5px;
				}
			}
		}
	}
	.topTitle{
		width: 100vh;
		height: 150px;
		position: fixed;
		bottom: 0;
		.btn{
			color: #fff;
			width: 100px;
			height: 40px;
			font-size: 14px;
			line-height: 40px;
			background: #508CFF;
			border-radius: 5px 5px 5px 5px;
			display: block;
			text-align: center;
			position: relative;
			bottom: -65px;
			left: 18vh;
		}
		
	}
	.popup{
		height: 157px;
		background: #FFFFFF;
		text{
			line-height: 50px;
			display: block;
			text-align: center;
			font-family: Roboto-Regular, Roboto;
			font-weight: 400;
			color: #000000;
			font-size: 16px;
		}
		.cancel{
			color: #F26D6D;
		}
	}
	.load-more{
		display: block;
		padding: 20px;
		margin: 0 auto;
		text-align: center;
	}
</style>